
import { VuexModule, Module, Action, Mutation, getModule, MutationAction } from 'vuex-module-decorators';
import store from '@/store';
import servers from '@/servers/index'
import { GetSocketModule } from "@/store/modules/GetSocketData";

// 公共方法
@Module({ dynamic: true, store, name: 'LocksAPI', namespaced: true })
class LocksAPI extends VuexModule {
  // state

  public getUserList: any[] = []//授权人、被授权人
  getDeviceItemList: any[] = []//获取钥匙下拉选接口
  oneStationList: any = {}//一条变电站数据
  bdzId=''
  get stationId(){
    return this.oneStationList.code
  } 
  // 获取某个变电站-(智能锁控、门禁控制、五防钥匙箱)的点位数
  get getxtInfo() {
    // console.log('this.stationId:', this.oneStationList.code);
    let xtInfo = GetSocketModule.getterAllAuxiliaryByStationId || {}
    var id = this.oneStationList.code
    var xtList = xtInfo[id] || []
    // console.log('xtList:',xtList);
    
    let xtobj = {
      '0201': [],//门禁控制
      '02': [],
      '07': [],//锁控系统
      '08': [],//五防钥匙箱
    }
    let objKeys = Object.keys(xtobj)
    xtList.map(k => {
      if (objKeys.indexOf(k.xtValue) >= 0) {
        xtobj[k.xtValue] = xtobj[k.xtValue] || []
        xtobj[k.xtValue].push(k)
      }
      if (objKeys.indexOf(k.sbValue) >= 0) {
        xtobj[k.sbValue] = xtobj[k.sbValue] || []
        xtobj[k.sbValue].push(k)
      }
    })

    console.log('xtobj:', xtobj);
    return xtobj
  }

  //授权人、被授权人
  @MutationAction({ mutate: ['getUserList'] })
  async getUser() {
    var list: any = await (servers as any)
      .getUser({ data: {} }).then((res: any) => {
        // console.log(res.data);
        return res.data
      })
    // console.log(list);
    return { getUserList: list }
  }
  //获取钥匙下拉选接口
  @MutationAction({ mutate: ['getDeviceItemList'] })
  async getDeviceItem() {
    var list: any = await (servers as any)
      .getDeviceItem({ data: {} }).then((res: any) => {
        // console.log(res.data);
        return res.data
      })
    // console.log(list);
    return { getDeviceItemList: list }
  }

  @Mutation
  setStationName(item: any) {
    // console.log('LocksAPIModule:',item);
    if (item.name) {
      this.oneStationList = item
    }
  }

}

export const LocksAPIModule = getModule(LocksAPI);
